﻿using Basic.UserModel.LoginLog;
using Basic.UserRepository;
using WeDonekRpc.Client;
using WeDonekRpc.Client.Attr;
using WeDonekRpc.Client.Ioc;
using WeDonekRpc.Helper;
using WeDonekRpc.Helper.Interface;

namespace Basic.UserCollect.Extend
{
    [ClassLifetimeAttr(ClassLifetimeType.SingleInstance)]
    internal class SaveLoginLog : ISaveLoginLog
    {
        private static readonly IDelayDataSave<LoginLogAdd> _SaveLog = new DelayDataSave<LoginLogAdd>(_Save, 1000, 20);

        private static void _Save ( ref LoginLogAdd[] datas )
        {
            using ( IocScope scope = RpcClient.Ioc.CreateScore() )
            {
                ILoginLogRepository repository = scope.Resolve<ILoginLogRepository>();
                repository.Adds(datas);
            }
        }

        public void AddLog ( LoginLogAdd add )
        {
            _SaveLog.AddData(add);
        }
    }
}
